package ArrayProcessPackage;
import stdlib.*;
public class TransformParenthese
{
    public static void main(String[] args)
    {
        Stack<String> stack = new Stack<String>();
        Stack<String> result = new Stack<String>();
        Stack<String> temp =new Stack<String>();
        for(String s: args)
        {
            stack.push(s);
            temp.push(s);
        }
        transform(stack,result);
        while(!result.isEmpty())
            StdOut.print(result.pop()+" ");
        StdOut.println("");
        while(!temp.isEmpty())
            StdOut.print(temp.pop()+" ");
        StdOut.println("");
    }
    private static void transform(Stack<String> stack,Stack<String> result)
    {
        int count = 0;
        
        while(!stack.isEmpty())
        {
            String str = stack.pop();
            if(str.equals(")"))
            {
                result.push(str);
                transform(stack,result);
                result.push("(");
                count++;
            }
            else
            {
                result.push(str);
                count++;
            }
            if(count==3)
                return;
        }
    }
}
